package Application.Widgets.FormattedTextFileds;

import Application.Widgets.ErrorReportWidget;

import javax.swing.*;
import java.text.NumberFormat;

public class TextFieldInteger extends JFormattedTextField
{
    private String WidgetName = "";

    public String getWidgetName() {
        return this.WidgetName;
    }
    public void setWidgetName(String name)
    {
        this.WidgetName = name;
    }
    public TextFieldInteger(int columns)
    {
        super(NumberFormat.getIntegerInstance());
        this.setColumns(columns);
        this.setFocusLostBehavior(JFormattedTextField.COMMIT);
    }

    public int getInteger(int integer)
    {
        try {
            return Integer.parseInt(this.getText());
        }catch (Exception ex)
        {
            ErrorReportWidget.errorReport.append(ex.getMessage()+"\n");
            ErrorReportWidget.errorReport.append("不合法的输入，位置："+this.getWidgetName()+"\n");
            ex.printStackTrace();
        }
            return integer;
    }

}
